#!/usr/bin/python
from scipy import stats
import numpy as np
import pylab

x_array = []
y_array = []

class Xian:
    def __init__(self,x_array,y_array):
        self.x= np.array(x_array)
        self.y= np.array(y_array)
        self.res = []
    def get_result():
        slope,intercept , r_value, p_value, slope_std_error = stats.linregress(self.x,self.y)
        self.res = [slope,intercept,r_value,p_value,slope_std_error]
        return res

    def run_result(self,res):
        intercept = res[1]
        slope = res[0] #res[0] is slope
        predict_y = intercept + slope * x
        predict_error = y -predict_y
        degree_of_freedom = len(x) - 2
        residual_std_error = np.sqrt(np.sum(predict_error **2) / degree_of_std_freedom)
        return predict_y

    def Graphy(self,x,y):
        pylab.plot(x,y,'o')
        pylab.plot(x,self.run_result(self.get_result()),'k-')
        pylab.show()
    
    def run (self):
        if self.x != None and self.y != None :
            self.Graphy()

def array_get():
    global x_array
    global y_array
    while True:
        try : 
            a = (float(raw_input("x >>  " )))
            b =  (float(raw_input(" y >> " )))
            x_array.append(a)
            y_array.append(b)
        except  ValueError:
            break
    
if __name__ =="__main__" :
    array_get()
    o = Xian(x_array,y_array)
    o.run()
    
